﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.ServiceModel.Security;
	using System.Text;


	/// <summary>
	/// Manages various functions of the users twitter account. 
	/// </summary>
	public class AccountClient : TwitterClient<IAccountClient>, 
		IAccountClient
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="AccountClient"/> class.
		/// </summary>
		/// <param name="username">The username.</param>
		/// <param name="password">The password.</param>
		public AccountClient(string username, string password)
			: base(username, password) { }

		#region IAccountClient Members


		/// <summary>
		/// Verifies if the user is able to log in with the current credentials.
		/// </summary>
		/// <returns>returns true if the user could login, otherwise false.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public VerifyResponse Verify()
		{
			try 
			{
				return this.Proxy.Verify();
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Ends the session of the current user if they are logged in.
		/// </summary>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public void EndSession()
		{
			try
			{
				this.Proxy.EndSession();
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
		}

		/// <summary>
		/// Updates the location information about the user.
		/// </summary>
		/// <param name="location">The location, currently not geo cordinates</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/> object. </returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User UpdateLocation(string location)
		{
			try
			{
				return this.Proxy.UpdateLocation(location);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Updates the delivery device the user wants to recieive notifications on. 
		/// </summary>
		/// <param name="device">The currently allowed devices</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/> object. </returns>
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User UpdateDeliveryDevice(DeliveryDevices device)
		{
			try
			{
				return this.UpdateDeliveryDevice(device.ToString().ToLower());
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Updates the delivery device the user wants to recieive notifications on. 
		/// </summary>
		/// <param name="device">The currently allowed devices</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/> object. </returns>
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User UpdateDeliveryDevice(string device)
		{
			try
			{
				return this.Proxy.UpdateDeliveryDevice(device);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Gets the current rate limit status of the user.
		/// </summary>
		/// <remarks>
		///		<para>
		///			This is the only method of twitters api that does not count
		///			against your allowed rate hits per user. 
		///		</para>
		/// </remarks>
		/// <returns>returns a <see cref="Amplify.Twitter.RateStatus"/> object.</returns>
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public RateStatus GetRateStatusLimit()
		{
			try
			{
				return this.Proxy.GetRateStatusLimit();
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		#endregion
	}
}
